 $(document).ready(function () {
    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green',
    });
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#submitForm").validate({
        rules: {
            account: {
                required: true,
                maxlength:100
            },
            name: {
                required: true,
                maxlength:100
            },
            phone: {
                required: true
            }
        },
        messages: {

            account: {
                required: icon+"请输入账号",
                maxlength:icon+"长度不能超过100"
            },
            name: {
                required: icon+"请输入系统用户姓名",
                maxlength:icon+"长度不能超过100"
            },
            phone: {
                required: icon+"请输入联系号码"
            }
        },
        submitHandler: function() {
            if($(".productTypeName").val()==""){
                layer.alert("请选择部门！",{ skin: 'layui-layer-molv',title :"系统提示" });
                return false;
            }
            $(".btn").attr('disabled', "true");
            // 暂时禁用提交按钮，等ajax结束之后再启用
            var formData = $("#submitForm").serialize();
            $.ajax({
                url: ctx + "/admin/admin/add",
                type: 'post',
                dataType: 'json',
                data: formData,
                success: function(data) {
                    $(".btn").removeAttr("disabled");
                    if (!data.success) {
                        layer.alert(data.info,{ skin: 'layui-layer-molv',title :"系统提示" });
                        return false;
                    }
                    var id = $("#id").val();
                    var msg = "编辑成功";
                    if(id == 0){
                        msg = "新增成功";
                    }
                    layer.msg(msg);
                    setTimeout('goList()', 800);
                },
                error: function(data) {
                    $(".btn").removeAttr("disabled");
                    layer.msg(data.info);
                }
            });
            return false;
            //阻止表单提交
        }
    });
});